﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetworkSimulator
{
    public class Path
    {
        public List<Link> links;

        // public List<Link> Links { get { return this.links; } }

        // Max usable bandwidth ResidualBandwidth
        // Ex: n(A) --4-> n(B) --3->  n(C) --2-> n(D) --3-> n(E)
        //     usable bandwidth of this path must be 2 (ResidualBandwidth = 2)
        public double ResidualBandwidth
        {
            get
            {
                if (this.links.Count > 0)
                {
                    double min = double.MaxValue;
                    foreach (Link link in this.links)
                    {
                        if (min > link.ResidualBandwidth)
                            min = link.ResidualBandwidth;
                    }
                    return min;
                }
                return 0;
            }
        }


        // Cost for this path
        public double cost;

        // Numbers of Hop (or node) in this path
        public int NumsNode
        {
            get
            {
                return this.links.Count;
            }
        }

        public List<Link> Links
        {
            get { return this.links; }
            set { this.links = value; }
        }

        // CONTRUCTOR
        public Path()
        {
            this.links = new List<Link>();
            //this.m_bw = 0;
            this.cost = 0;
        }

        public Path(Path path)
        {
            this.links = path.links;
            //this.m_bw = path.m_bw;
            this.cost = path.cost;
        }

        public void Add(Link link)
        {
            this.links.Add(link);
        }

        public void Reverse()
        {
            this.links.Reverse();
        }

        public bool isEmpty()
        {
            if (this.links.Count > 0)
                return false;
            return true;
        }

        public override string ToString()
        {
            string s = "";
            if (links.Count > 0)
            {
                s += links[0].Source.Id;
                foreach (Link link in links)
                {
                    s += "->" + link.Destination.Id;
                }
            }
            return s;
        }

        //public void Print()
        //{
        //    if (links.Count > 0)
        //    {
        //        Console.Write("{0} ", links[0].Source.Id);

        //        foreach (Link link in links)
        //        {
        //            Console.Write("-> {0}", link.Destination.Id);
        //        }
        //        Console.WriteLine();
        //    }
        //}
    }
}
